package com.menggudf.service.impl;

import com.menggudf.entity.BmiRecord;
import com.menggudf.mapper.BmiRecordDao;
import com.menggudf.service.BmiRecordService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (BmiRecord)表服务实现类
 *
 * @author makejava
 * @since 2025-02-20 16:58:26
 */
@Service("bmiRecordService")
public class BmiRecordServiceImpl implements BmiRecordService {
    @Resource
    private BmiRecordDao bmiRecordDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public BmiRecord queryById(Integer id) {
        return this.bmiRecordDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param bmiRecord 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<BmiRecord> queryByPage(BmiRecord bmiRecord, PageRequest pageRequest) {
        long total = this.bmiRecordDao.count(bmiRecord);
        return new PageImpl<>(this.bmiRecordDao.queryAllByLimit(bmiRecord, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param bmiRecord 实例对象
     * @return 实例对象
     */
    @Override
    public BmiRecord insert(BmiRecord bmiRecord) {
        this.bmiRecordDao.insert(bmiRecord);
        return bmiRecord;
    }

    /**
     * 修改数据
     *
     * @param bmiRecord 实例对象
     * @return 实例对象
     */
    @Override
    public BmiRecord update(BmiRecord bmiRecord) {
        this.bmiRecordDao.update(bmiRecord);
        return this.queryById(bmiRecord.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.bmiRecordDao.deleteById(id) > 0;
    }
}
